home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
internet
/
tcppack
/
tcppackb.lzh
/
src
/
libnetwork
/
user.c
< prev
Wrap
C/C++ Source or Header
|
1994-08-05
|
4KB
|
204 lines
/*
* user.c
*
* Copyright (C) 1994 First Class Technology.
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"tcpipdrv.h"
#include"network.h"
_ti_func search_ti_entry (void);
static char _num[] = "0123456789abcdef";
/************************************************
* *
************************************************/
int
isipaddr (char *src)
{
if (strspn (src, "0123456789.") == strlen (src))
return 1;
else
return 0;
}
/************************************************
* *
************************************************/
struct netent *
getnetbyname (char *name)
{
_ti_func func = search_ti_entry ();
if (func)
return (struct netent *)func (_TI_getnetbyname, (long *)name);
return NULL;
}
/************************************************
* *
************************************************/
struct netent *
getnetbyaddr (long net, int type)
{
_ti_func func = search_ti_entry ();
if (func)
{
long argv[2];
argv[0] = net;
argv[1] = (long)type;
return (struct netent *)func (_TI_getnetbyaddr, argv);
}
return NULL;
}
/************************************************
* *
************************************************/
struct servent *
getservbyport (int port, char *proto)
{
_ti_func func = search_ti_entry ();
if (func)
{
long argv[2];
argv[0] = port;
argv[1] = (long)proto;
return (struct servent *)func (_TI_getservbyport, argv);
}
return NULL;
}
/************************************************
* *
************************************************/
struct servent *
getservbyname (char *name, char *proto)
{
_ti_func func = search_ti_entry ();
if (func)
{
long argv[2];
argv[0] = (long)name;
argv[1] = (long)proto;
return (struct servent *)func (_TI_getservbyname, argv);
}
return NULL;
}
/************************************************
* *
************************************************/
struct protoent *
getprotobyname (char *name)
{
_ti_func func = search_ti_entry ();
if (func)
return (struct protoent *)func (_TI_getprotobyname, (long *)name);
return NULL;
}
/************************************************
* *
************************************************/
struct protoent *
getprotobynumber (int num)
{
_ti_func func = search_ti_entry ();
if (func)
return (struct protoent *)func (_TI_getprotobynumber, (long *)num);
return NULL;
}
/************************************************
* *
************************************************/
long
a2n_ipaddr (char *s)
{
long n;
int i;
n = 0;
for (i = 24; i >= 0; i -= 8)
{
n |= (long) atoi (s) << i;
s = strchr (s, '.');
if (!s)
break;
s++;
}
return n;
}
/************************************************
* *
************************************************/
char *
n2a_ipaddr (long a, char *dst)
{
sprintf (dst, "%d.%d.%d.%d", (a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff);
return dst;
}
/************************************************
* *
************************************************/
char *
a2n_eaddr (char *s, char *d, int max)
{
char *p, *q;
int i;
p = d;
q = s;
for (i = 0; i < max; i++)
{
*p++ = (unsigned char) atoi (q);
q = strchr (q, ':');
if (!s)
break;
q++;
}
if (i + 1 < max)
*p++ = '\0';
return d;
}
/************************************************
* *
************************************************/
char *
n2a_eaddr (char *s, char *dst, int len)
{
int i;
char *p, *q;
p = dst;
q = s;
for (i = 0; i < len; i++)
{
unsigned char c;
c = *q++;
*p++ = _num[(c >> 4) & 0xf];
*p++ = _num[c & 0xf];
*p++ = ':';
}
*(p - 1) = '\0';
return dst;
}